home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / src / test / memmodel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-13  |  2.1 KB  |  94 lines

  1. /*  $Id: memmodel.c,v 1.3 1995/02/13 14:56:46 jan Exp $
  2.  
  3.     Copyright (c) 1991 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: Determine machines memory-model
  7. */
  8.  
  9. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  10. This program   was written  to  determine the  memory  model   of your
  11. machine.  It may be used when writing a new md-machine.h file.
  12.  
  13. Compile this file using:
  14.  
  15.     % cc -o m-model m-model.c
  16.     % ./m-model
  17.     Memory layout:
  18.  
  19.         Text at 0x2290
  20.         Global variable at 0x40d0
  21.         Local variable at 0xeffff938
  22.         malloc() at 0x61a0
  23.         C-Stack grows Downward
  24.  
  25.     No special declarations needed in "md.h"
  26.  
  27.     %
  28. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  29.  
  30. #include <stdio.h>
  31.  
  32. #define K * 1024
  33. #define MAX_DECL 100
  34.  
  35. int    global_var;
  36.  
  37. char *
  38. sub()
  39. { char buf[10];
  40.  
  41.   return buf;
  42. }
  43.  
  44. main(argc, argv)
  45. int argc;
  46. char *argv[];
  47. { char buf[10];
  48.   unsigned long gva = (unsigned long) &global_var;
  49.   int stack_up = (sub() > buf);
  50.   char *decl[MAX_DECL];
  51.   int ndecl = 0;
  52.  
  53. #ifdef VERBOSE
  54.   printf("Memory layout:\n\n");
  55.   printf("\tText at 0x%x\n", sub);
  56.   printf("\tGlobal variable at 0x%x\n", gva);
  57.   printf("\tLocal variable at 0x%x\n", buf);
  58.   printf("\tmalloc() at 0x%x\n", malloc(10));
  59.   printf("\tC-Stack grows %sward\n", stack_up ? "Up" : "Down");
  60. #endif     
  61.  
  62.   if      ( (gva & 0xf0000000L) == 0x80000000L )
  63.     decl[ndecl++] = "DATA_AT_0X8=1;";
  64.   else if ( (gva & 0xf0000000L) == 0x40000000L )
  65.     decl[ndecl++] = "DATA_AT_0X4=1;";
  66.   else if ( (gva & 0xf0000000L) == 0x20000000L )
  67.     decl[ndecl++] = "DATA_AT_0X2=1;";
  68.   else if ( (gva & 0xf0000000L) == 0x10000000L )
  69.     decl[ndecl++] = "DATA_AT_0X1=1;";
  70.   else if ( (gva & 0xf0000000L) )
  71.   { printf("PROBLEM: Memory model not supported; see \"pl-incl.h\"\n");
  72.     exit(1);
  73.   }
  74.   
  75.   if ( stack_up )
  76.     decl[ndecl++] = "STACK_DIRECTION=1;";
  77.   else
  78.     decl[ndecl++] = "STACK_DIRECTION=-1;";
  79.  
  80.   if ( !malloc(200000) )
  81.   { printf("PROBLEM: malloc(200000) fails; see \"pl-os.c\"\n");
  82.     exit(1);
  83.   }
  84.  
  85.   if ( ndecl > 0 )
  86.   { int n;
  87.  
  88.     for(n=0; n<ndecl; n++)
  89.       printf("%s\n", decl[n]);
  90.   }
  91.  
  92.   exit(0);
  93. }
  94.